#include <iostream>
#include <unordered_map> 
#include <string>
using namespace std;

int main(){
	freopen("in.txt","r",stdin);
	int n;
	cin >> n;
	char s[100];
	string EToM[13] = {"tret","jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec" },
	EToMH[13] = {"tret", "tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};
	unordered_map<string,int> MToE,MToEH;
	for(int i=0; i<13; i++){
		MToE[EToM[i]] = i;
		MToEH[EToMH[i]] = i;
	}
	cin.get();
	for(int i=0; i<n; i++){
		cin.getline(s,100,'\n');
		if( s[0]>='0'&&s[0]<='9' ) {
			int c = 0;
			sscanf(s,"%d",&c);
			int a[2] = { },i = 0;
			while( c ){
				a[i++] = c%13;
				c /= 13;
			}
			if( a[1] ) cout << EToMH[a[1]];
			if( a[1] && a[0] ) cout << " ";
			if( !(a[1] && a[0]==0) ) cout << EToM[a[0]];
			cout << endl;
		}else {
			string mar[2] = {};
			int j = 0,k = 0;
			char *p = s;
			for(; s[k]!='\0'; k++){
				if( s[k]==' ' ) {
					mar[j++] = string(p,s+k-p);
					p = s+k+1;
				}
			} 
			mar[j++] = string(p,s+k-p);
			int c = 0;
			if( mar[1]=="" ){
				if( MToE.find(mar[0])!=MToE.end() ) c = MToE[mar[0]];
				else c = MToEH[mar[0]]*13;
			} 
			else c = MToEH[mar[0]]*13 + MToE[mar[1]];
			cout << c << endl;
		}
	}
	return 0;
}

